import request from '@/utils/request'
import { AxiosResponse } from 'axios'
import {
  AdminAddTeacherParams,
  AdminUpadeTeacherParams,
  AdminGetTeacherRes,
  BasePageQuery,
} from './type'
import qs from 'qs'

// 项目用户相关的请求地址
enum Teacher_API {
  POST_ADD_TEACHER_PAGE = '/teaching_system/teach/addTeach',
  GET_TEACHER_PAGE = '/teaching_system/teach/getAllTeach',
  GET_TEACHER_BYID = '/teaching_system/teach/getById/{teachId}',
  DELETE_TEACHER_BYID = '/teaching_system/teach/deleteTeach/{teachId}',
  PUT_UPDATE_TEACHER = '/teaching_system/teach/updateTeach',
}

/**
 * 添加教师
 * @param {object} params 新增教师
 * @param {number} params.teacherId 教师职工号
 * @param {string} params.name 教师姓名
 * @param {string} params.gender 教师性别(male/female)
 * @param {object} params.birthday 教师生日
 * @param {string} params.department 教师所属学院
 * @param {string} params.title 教师职称
 * @param {string} params.phone 教师电话号码
 * @param {string} params.address 教师住址
 * @param {string} params.idCard 教师身份证号
 * @returns
 */
export const adminAddTeacher = (params: AdminAddTeacherParams) =>
  request.post<any, AxiosResponse<any>>(
    Teacher_API.POST_ADD_TEACHER_PAGE,
    params,
  )

/**
 * 删除教师
 * @param {string} teachId
 * @returns
 */
export const adminDeleteTeacher = (id: number) =>
  request.delete<any, AxiosResponse<any>>(
    Teacher_API.DELETE_TEACHER_BYID.replace('{teachId}', id.toString()),
  )

/**
 * 获取教师列表
 * @param {string} pageNum 页码
 * @param {string} pageSize 每页记录数
 * @returns
 */
export const adminGetTeacher = (params: BasePageQuery) =>
  request.get<any, AxiosResponse<AdminGetTeacherRes>>(
    Teacher_API.GET_TEACHER_PAGE + '?' + qs.stringify(params),
  )

/**
 * 根据id获得教师信息
 * @param {string} teachId
 * @returns
 */
export const getTeacherById = (teachId: number) =>
  request.get<any, AxiosResponse<AdminGetTeacherRes>>(
    Teacher_API.GET_TEACHER_BYID.replace('{teacherId}', teachId.toString()),
  )

/**
 * 修改教师
 * @param {object} params UpdateTeachForm
 * @param {number} params.teacherId 教师职工号
 * @param {string} params.name 教师姓名
 * @param {string} params.gender 教师性别(male/female)
 * @param {object} params.birthday 教师生日
 * @param {string} params.department 教师所属学院
 * @param {string} params.title 教师职称
 * @param {string} params.phone 教师电话号码
 * @param {string} params.address 教师住址
 * @param {string} params.idCard 教师身份证号
 * @returns
 */
export const adminUpadeTeacher = (params: AdminUpadeTeacherParams) =>
  request.put<any, AxiosResponse<string>>(
    Teacher_API.PUT_UPDATE_TEACHER,
    params,
  )
